#include<iostream>
using namespace std;
const int N = 1e3 + 10;
int n;
int stk[N];
int tt;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		while (tt && stk[tt] >= a) {
			tt--;
		}
		if (tt) {
			cout << stk[tt] << " ";
		}
		else {
			cout << -1 << endl;
		}
		stk[++tt] = a;		
	}
	return 0;
}